package org.yohailong.mock.client.client;

import com.google.gson.Gson;
import io.reactivex.rxjava3.disposables.Disposable;
import org.yohailong.mock.client.api.DemoApi;
import org.yohailong.mock.client.network.RetrofitManager;
import org.yohailong.mock.client.pojo.req.DateReq;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 朱海龙
 * 2024/4/28 17:23
 */
public class AndroidClient {

    private DemoApi demoApi;

    public AndroidClient() {
        RetrofitManager.init(null, "http://127.0.0.1:8080");
        demoApi = RetrofitManager.getInstance().createServerApi(DemoApi.class);
    }


    public Disposable uploadBirthday() {
        DateReq req = new DateReq();
        req.setName("castlong");
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println(format);
        req.setBirthday(format);
        return demoApi.uploadDate(req)
                .subscribe(response -> {
                    System.out.println(new Gson().toJson(response));
                }, Throwable::printStackTrace, () -> System.out.println("over"));

    }


}
